package com.control.qct.businesssteward.activity;

import android.support.v4.widget.DrawerLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import com.control.qct.businesssteward.R;
import com.control.qct.businesssteward.adapter.OrderAdapter;
import com.control.qct.businesssteward.base.BaseActivity;
import com.control.qct.businesssteward.entity.TabEntity;
import com.control.qct.businesssteward.fragment.ChargebackSearchOrderFragment;
import com.control.qct.businesssteward.model.OrderListModel;
import com.control.qct.businesssteward.utils.ScreenUtil;
import com.flyco.tablayout.CommonTabLayout;
import com.flyco.tablayout.listener.CustomTabEntity;
import com.flyco.tablayout.listener.OnTabSelectListener;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * 退单
 * Created by Administrator on 2018/1/24 0024.
 */

public class ChargeBackActivity extends BaseActivity implements OnTabSelectListener,OrderAdapter.ICallbackClickListener {
    @BindView(R.id.ctl_order_top)
    CommonTabLayout mCtlChargebackTop;
    @BindView(R.id.fl_search_order_content)
    FrameLayout mFlSearchOrderContent;
    @BindView(R.id.dl_menu)
    public DrawerLayout mDlMenu;
    @BindView(R.id.rv_charge_back)
    RecyclerView mRvChargeBack;

    private final String[] mTitles = {"全部", "已完成", "已退单"};
    private ArrayList<CustomTabEntity> mTabEntities = new ArrayList<>();
    private List<OrderListModel.DatasBean> mDatasBeanList = new ArrayList<>();
    private OrderAdapter mOrderAdapter;


    public ChargeBackActivity() {
        super(R.layout.activity_chargeback);
    }

    @Override
    protected void initView() {
        mTabEntities.clear();
        setLeftIcon(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        setTitle("退单");
        setRightIcon("筛选", new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mDlMenu.openDrawer(mFlSearchOrderContent);
            }
        });
        //设置侧滑菜单布局
        ViewGroup.LayoutParams params = mFlSearchOrderContent.getLayoutParams();
        params.width = (int) (ScreenUtil.getScreenWidthPix(this) * 0.85);
        mFlSearchOrderContent.setLayoutParams(params);
        replaceFragment(R.id.fl_search_order_content, new ChargebackSearchOrderFragment());

        for (int i = 0; i < mTitles.length; i++) {
            mTabEntities.add(new TabEntity(mTitles[i], 0, 0));
        }
        mCtlChargebackTop.setTabData(mTabEntities);
        mCtlChargebackTop.setOnTabSelectListener(this);
        mRvChargeBack.setLayoutManager(new LinearLayoutManager(this));
        mOrderAdapter = new OrderAdapter(mDatasBeanList);
        mRvChargeBack.setAdapter(mOrderAdapter);

    }

    @Override
    public void onTabSelect(int position) {

    }

    @Override
    public void onTabReselect(int position) {

    }

    @Override
    public void onBackPressed() {
        if (mDlMenu.isDrawerOpen(mFlSearchOrderContent)){
            mDlMenu.closeDrawers();
        }else {
            super.onBackPressed();
        }
    }

    @Override
    public void onClickListener(int position) {

    }
}
